﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using Microsoft.Windows.Controls;
using ScrumMagic;
using Microsoft.Windows.Controls.Ribbon;
//using ProjectList.ScrumMagicDataSetTableAdapters;


namespace ScrumMagic
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class ProjectCardForm : CommonForm

    {
        string PRODUCT_ID;
        public ProjectCardForm(string pr_id)
        {
            PRODUCT_ID = pr_id;
            InitializeComponent();
        }

        static string StrDate;
        static string StrStatus;
        static string StrMaster;
        static string StrOwner;

        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            try
            {
                SqlCommand cmd = DBController.MainConnection.CreateCommand();
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = "Select Name from Project where id=" + PRODUCT_ID + ";";
                SqlDataReader reader = cmd.ExecuteReader();
                reader.Read();
                label_Name.Content = reader[0].ToString();
                reader.Close();

                cmd.CommandText = "Select Start_Date from Project where id=" + PRODUCT_ID + ";";
                reader = cmd.ExecuteReader();
                reader.Read();
                StrDate = reader[0].ToString();
                StrDate=StrDate.Remove(10);
                textBox1.Text = StrDate;
                reader.Close();

                cmd.CommandText = "select [Status].[Name] from Project,[Status] where ([Status].Id= Project.Status_Id) AND  Project.Id=" + PRODUCT_ID;
                reader = cmd.ExecuteReader();
                reader.Read();
                StrStatus = reader[0].ToString();
                textBox2.Text = StrStatus; 
                reader.Close();


                cmd.CommandText = @"Select FirstName,lastName from  [User],RoleInProject 
where (RoleInProject.Project_Id=" + PRODUCT_ID + " and RoleInProject.Role_Id=(select Id from [Role] where [Role].[Name]='Project Owner') and RoleInProject.User_Id=[User].Id)";
                reader = cmd.ExecuteReader();
                reader.Read();
                StrOwner = reader[0].ToString() + " " + reader[1].ToString();
                textBox3.Text = StrOwner;
                reader.Close();

                cmd.CommandText = @"Select FirstName,lastName from  [User],RoleInProject 
where (RoleInProject.Project_Id=" + PRODUCT_ID + " and RoleInProject.Role_Id=(select Id from [Role] where [Role].[Name]='Scrum Master') and RoleInProject.User_Id=[User].Id)";
                reader = cmd.ExecuteReader();
                reader.Read();
                StrMaster = reader[0].ToString() + " " + reader[1].ToString();
                textBox4.Text = StrMaster;
                reader.Close();




                cmd.CommandText = @"Select FirstName,LastName,EMail,[Name] from [User],[Role],RoleInProject where 
            [Role].Id=RoleInProject.Role_Id and
            RoleInProject.Project_Id=" + PRODUCT_ID + @" and 
            [User].Id=RoleInProject.User_id";


                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                DataTable table = new DataTable();
                adapter.Fill(table);

                dataGrid.ItemsSource = table.DefaultView;
            }
            catch (Exception ex) 
            {
                MessageBox.Show(ex.ToString());
                
                //Close();
            }

                 
        }

   
        private void OnGridMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {

        }

    }
}